/*******************************************************************************
 * Copyright 2010 Simon Mieth
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package cn.kkdlk.parse.dxf.generator.table;

import cn.kkdlk.parse.DraftDocument;
import cn.kkdlk.parse.common.Layer;
import cn.kkdlk.parse.dxf.generator.DXFGenerationContext;
import cn.kkdlk.parse.dxf.generator.DXFOutput;
import cn.kkdlk.parse.dxf.generator.DXFTableGenerator;
import cn.kkdlk.parse.dxf.generator.conf.DXFProfile;
import cn.kkdlk.parse.io.GenerationException;
import cn.kkdlk.parse.util.Constants;

public class DXFLayerTableHandler implements DXFTableGenerator {

    /*
     * (non-Javadoc)
     *
     * @see org.kabeja.dxf.generator.DXFTableGenerator#getTableType()
     */
    public String getTableType() {

        return Constants.TABLE_KEY_LAYER;
    }

    /*
     * (non-Javadoc)
     *
     * @see
     * org.kabeja.dxf.generator.DXFTableGenerator#output(org.kabeja.dxf.DXFDocument
     * , org.kabeja.dxf.generator.DXFOutput)
     */
    public void output(DraftDocument doc, DXFOutput output, DXFGenerationContext context, DXFProfile type) throws GenerationException {
        output.output(70, doc.getLayers().size());
        for (Layer layer : doc.getLayers()) {
            output.output(2, layer.getName());
            output.output(70, layer.getFlags());
            output.output(62, layer.getColor());
            output.output(6, layer.getLineType().getName());
            if (!layer.isPlottable()) {
                output.output(290, 0);
            }
            output.output(370, layer.getLineWeight());
            output.output(390, layer.getPlotStyle());
        }
    }

}
